package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class OthersStudentDao implements BaseStudentDao {
   private static ArrayList<Student> stu =new ArrayList<>();
   static {
       Student stu1=new Student("heima001","李丹丹","23","1999");
       Student stu2=new Student("heima002","李文杰","23","1999");
       stu.add(stu1);
       stu.add(stu2);
   }
    public boolean addStudenet(Student student) {

            return stu.add(student);
    }
//查看学生
    public Student[] findAllStudent() {

       return  stu.toArray(new Student[stu.size()]);
    }
//删除学生
    public void deleteStudent(String id) {
       int index =getIndex(id);
       stu.remove(index);
    }

    //获取指定学号在数组中的索引
    public int getIndex(String id){
        int index=-1;
        for (int i = 0; i < stu.size(); i++) {
            if (stu.get(i)!=null &&id.equals(stu.get(i).getId())){
                index=i;
            }
        }
        return index;
    }
//修改学生
    public void updateStudent(Student student, String id) {
        int index=getIndex(id);
        stu.set(index,student);
    }
}
